package cn.mooncode.basketballManage.service.impl;

import cn.mooncode.basketballManage.pojo.RespBean;
import cn.mooncode.basketballManage.pojo.RespPageBean;
import cn.mooncode.basketballManage.service.ITrainService;
import cn.mooncode.basketballManage.mapper.TrainMapper;
import cn.mooncode.basketballManage.pojo.Train;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jwz
 * @since 2021-03-28
 */
@Service
public class TrainServiceImpl extends ServiceImpl<TrainMapper, Train> implements ITrainService {

    @Autowired
    private TrainMapper trainMapper;

    /**
     * 获取所有训练信息
     * @param currentPage
     * @param size
     * @param train
     * @return
     */
    @Override
    public RespPageBean getAllTrains(Integer currentPage, Integer size, Train train) {
        Page<Train> page = new Page<>(currentPage, size);
        IPage<Train> iPage = trainMapper.getAllTrains(page, currentPage, size);
        return new RespPageBean(iPage.getTotal(), iPage.getRecords());
    }

    /**
     * 获取当前用户所有训练信息
     * @param currentPage
     * @param size
     * @param train
     * @param tid
     * @return
     */
    @Override
    public RespPageBean getCurrentTrains(Integer currentPage, Integer size, Train train, Integer tid) {
        Page<Train> page = new Page<>(currentPage, size);
        IPage<Train> iPage = trainMapper.getCurrentTrains(page, currentPage, size, tid);
        return new RespPageBean(iPage.getTotal(), iPage.getRecords());
    }

    /**
     * 添加训练结果
     * @param id
     * @param result
     * @return
     */
    @Override
    public RespBean addResult(Integer id, String result) {
        if (trainMapper.addResult(id, result)) {
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }
}
